var JSEncrypt = require("jsencrypt") //存放路径

//传入数据，公钥私钥
module.exports = {

    //加密：
    jiami(dat, publicKey) { //需要加密的数据 rsa公钥
        let data;
        if (typeof dat === 'string') {
            data = dat
        } else {
            data = JSON.stringify(dat)
        }
        let encrypt = new JSEncrypt();
        encrypt.setPublicKey(publicKey);
        let encryptMsg = encrypt.encrypt(data);
        return encryptMsg;
    },

    //解密
    jiemi(data, privateKey) { //需要解密的数据， rsa私钥
        let decrypt = new JSEncrypt();
        decrypt.setPrivateKey(privateKey);
        // console.log(data, privateKey)
        let decryptMsg = decrypt.decrypt(data);
        return decryptMsg;
    }
}